package main

import "fmt"

func main() {
	way1()
	way2()

}

func way1() {
	var beforeChangedMap = map[string]int{"a": 0, "b": 0, "c": 2}

	fmt.Println(beforeChangedMap)

	changedMap := map[int]string{}
	for key, value := range beforeChangedMap {
		changedMap[value] = key
	}
	fmt.Println(changedMap)
	// 问题：如果原 map 的值不唯一，就会少一些值
	// map[a:0 b:0 c:2]
	// map[0:b 2:c]
}

func way2() {
	var beforeChangedMap = map[string]int{"a": 0, "b": 0, "c": 2}

	fmt.Println(beforeChangedMap)

	// 采用多值 map 来解决
	changedMap := map[int][]string{}
	for key, value := range beforeChangedMap {
		changedMap[value] = append(changedMap[value], key)
	}
	fmt.Println(changedMap) // map[0:[a b] 2:[c]]

}
